/*
 * 行车数据分析
 * */
require(['echarts3'/*, 'highcharts'*/, 'zTreeCheckbox', 'date'], function (echarts) {

    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('container'));

    // 请求参数
    var postData = {};

    // DOIT: 2016-12-19 获取请求参数
    var getPostData = function () {
        // 左侧树选择车辆，获取carId
        var nodes = commonFun.getLeftTreeSelectedNodes();
        if (nodes && nodes.length > 0) {
            postData.carId = nodes[0].id;
        } else {
            $.messager.alert("警告", "请先选择一辆车", "info");
            return false;
        }

        // 获取开始、结束时间
        var date = $('#date_val').val();
        var beginTime = $('#_top_date_0').val();
        var endTime = $('#_top_date_1').val();

        if (!date || !beginTime || !endTime) {
            $.messager.alert("警告", "请先选择日期和时间段。", "info");
            return false;
        }

        postData.beginTime = date + ' ' + beginTime;
        postData.endTime = date + ' ' + endTime;

        console.log(postData);
        return true;
    }

    // DOIT: 2016-12-19 封装-获取数据请求方法
    var getData = function (url, postData, callback) {
        $.ajaxExt({
            url: url,
            data: postData
        }).done(function (data) {
            console.log(data);

            if (data && data.length > 0) {
                callback(data);
            } else {
                // 清空图表
                myChart.clear();

                // 提示
                $.messager.alert("警告", "该图表没有数据。", "info");
            }
        });
    }

    // 乘法
    function accMul(arg1, arg2) {
        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();

        try {
            m += s1.split(".")[1].length
        } catch (e) {
        }

        try {
            m += s2.split(".")[1].length
        } catch (e) {
        }

        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
    };

    // DOIT: 2016-12-19 监听触发事件
    $('.func_btn').click(function () {
        var type = $(this).attr('data');
        postData.type = type;

        if (getPostData()) {
            if (type == 1) {// 发动机-行车记录分析
                $('#title_bar').text('发动机-行车记录分析');
                getData("/carDataAna/getCarRecodeAnaData.htm", postData, initCarRecodeAnaChart);
            } else if (type == 2) {// 发动机-外特性曲线图
                alert('维护中');
            } else if (type == 3) {// 发动机-发动机功率图
                $('#title_bar').text('发动机-发动机功率图');
                getData("/carDataAna/getEnginePowerChartData.htm", postData, initEnginePowerChart);
            } else if (type == 4) {// 电池-电压电流图表
                $('#title_bar').text('电池-电压电流图表');
                getData("/carDataAna/getBatteryVoltCurrChartData.htm", postData, initBatteryVoltCurrChart);
            } else if (type == 5) {// 电池-续航里程分析
                $('#title_bar').text('电池-续航里程分析');
                getData("/carDataAna/getMileageAnalChartData.htm", postData, initMileageAnalChart);
            } else if (type == 6) {// 电机-电压电流图表
                $('#title_bar').text('电机-电压电流图表');
                getData("/carDataAna/getElecVoltCurrChartData.htm", postData, initElecVoltCurrChart);
            } else if (type == 7) {// 电机-车速转矩图表
                $('#title_bar').text('电机-车速转矩图表');
                getData("/carDataAna/getElecSpeedTorqueChartData.htm", postData, initElecSpeedTorqueChart);
            }
        }

    });

    // DOIT: 2016-12-19 生成 “发动机-行车记录分析” 图表
    var initCarRecodeAnaChart = function (data) {
        // 清空图表
        myChart.clear();

        var colors = ['#2c82ca', '#eee657', '#fcb940', '#fc6042', '#3bc5ed', '#d87737', '#53dc60', '#8771ce', '#e25979', '#35b6cd', '#203079', '#e2dd31'];
        var names = ['瞬时油耗', '油门踏板开度', '电子节气开度', '氧浓度', '进气温度', '进气压力', '车速', '转速', '机油压力', '水温', '前气压', '后气压'];
        var units = ['L/h', '%', '%', '%', '℃', 'mpa', 'km/h', 'r/min', 'mpa', '℃', 'mpa', 'mpa'];

        var spdOfMotVhiArr = [];
        var engiRtteSpdArr = [];
        var instFuelCsutArr = [];
        var acltPedalOpeArr = [];
        var electThroOpeArr = [];
        var oxygenConcenArr = [];
        var engiAirAdmissionTeptArr = [];
        var airAdmissionPrsArr = [];
        var engiWteTpteArr = [];
        var engiEngnOilPrsArr = [];
        var preAirPrsArr = [];
        var lastAirPrsArr = [];

        for (var i = 0; i < data.length; i++) {
            instFuelCsutArr.push([data[i].rcrdTime, (data[i].instFuelCsut && data[i].instFuelCsut > 0) ? data[i].instFuelCsut : 0])
            acltPedalOpeArr.push([data[i].rcrdTime, (data[i].acltPedalOpe) ? data[i].acltPedalOpe : 0])
            electThroOpeArr.push([data[i].rcrdTime, (data[i].electThroOpe) ? data[i].electThroOpe : 0])
            oxygenConcenArr.push([data[i].rcrdTime, (data[i].oxygenConcen) ? data[i].oxygenConcen : 0])
            engiAirAdmissionTeptArr.push([data[i].rcrdTime, (data[i].engiAirAdmissionTept && data[i].engiAirAdmissionTept > 0) ? data[i].engiAirAdmissionTept : 0])
            airAdmissionPrsArr.push([data[i].rcrdTime, (data[i].airAdmissionPrs && data[i].airAdmissionPrs > 0) ? data[i].airAdmissionPrs : 0])
            spdOfMotVhiArr.push([data[i].rcrdTime, (data[i].spdOfMotVhi && data[i].spdOfMotVhi > 0) ? data[i].spdOfMotVhi : 0])
            engiRtteSpdArr.push([data[i].rcrdTime, (data[i].engiRtteSpd && data[i].engiRtteSpd > 0) ? data[i].engiRtteSpd : 0])
            engiEngnOilPrsArr.push([data[i].rcrdTime, (data[i].engiEngnOilPrs && data[i].engiEngnOilPrs > 0) ? data[i].engiEngnOilPrs : 0])
            engiWteTpteArr.push([data[i].rcrdTime, (data[i].engiWteTpte && data[i].engiWteTpte > 0) ? data[i].engiWteTpte : 0])
            preAirPrsArr.push([data[i].rcrdTime, (data[i].preAirPrs && data[i].preAirPrs > 0) ? data[i].preAirPrs : 0])
            lastAirPrsArr.push([data[i].rcrdTime, (data[i].lastAirPrs && data[i].lastAirPrs > 0) ? data[i].lastAirPrs : 0])
        }

        // 指定图表的配置项和数据
        var option = {

            color: colors,

            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = param.value[0] + '<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                left: '10%',
                right: '18%',
                bottom: '30%',
                borderColor: '#c0c0c0',
                borderWidth: 1
            },
            toolbox: {
                feature: {
                    dataView: {show: false, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: false}
                }
            },
            legend: {
                bottom: '5%',
                selectedMode: true,
                data: names,
                selected: {
                    '瞬时油耗': false,
                    '油门踏板开度': false,
                    '电子节气开度': false,
                    '氧浓度': false,
                    '进气温度': false,
                    '进气压力': false,
                    '车速': true,
                    '转速': true,
                    '机油压力': false,
                    '水温': false,
                    '前气压': false,
                    '后气压': false,
                }
            },
            dataZoom: [
                {
                    type: 'inside',
                    start: 0,
                    end: 4
                }, {
                    start: 0,
                    end: 4,
                    xAxisIndex: [0],
                    bottom: '15%',
                    handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                    handleSize: '80%',
                    handleStyle: {
                        color: '#fff',
                        shadowBlur: 3,
                        shadowColor: 'rgba(0, 0, 0, 0.6)',
                        shadowOffsetX: 2,
                        shadowOffsetY: 2
                    }
                }
            ],
            xAxis: [
                {
                    type: 'time',
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisTick: {
                        show: true,
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '          L/H',
                    min: 0,
                    max: 80,
                    position: 'right',
                    nameLocation: 'end',
                    interval: 10,
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                },
                {
                    type: 'value',
                    name: '          %',
                    min: -100,
                    max: 100,
                    position: 'right',
                    interval: 25,
                    offset: 40,
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                },
                {
                    type: 'value',
                    name: '          ℃',
                    min: 0,
                    max: 160,
                    position: 'right',
                    interval: 20,
                    offset: 80,
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                },
                {
                    type: 'value',
                    name: '              mpa',
                    min: 0,
                    max: 2000,
                    position: 'right',
                    interval: 250,
                    offset: 120,
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                },
                {
                    type: 'value',
                    name: 'km/h          ',
                    min: 0,
                    max: 160,
                    position: 'left',
                    interval: 20,
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                },
                {
                    type: 'value',
                    name: 'r/min               ',
                    min: 0,
                    max: 3200,
                    offset: 40,
                    position: 'left',
                    interval: 400,
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: instFuelCsutArr
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: acltPedalOpeArr
                },
                {
                    name: names[2],
                    type: 'line',
                    yAxisIndex: 1,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: electThroOpeArr
                },
                {
                    name: names[3],
                    type: 'line',
                    yAxisIndex: 1,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: oxygenConcenArr
                },
                {
                    name: names[4],
                    type: 'line',
                    yAxisIndex: 2,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: engiAirAdmissionTeptArr
                },
                {
                    name: names[5],
                    type: 'line',
                    yAxisIndex: 3,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: airAdmissionPrsArr,
                },
                {
                    name: names[6],
                    type: 'line',
                    yAxisIndex: 4,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: spdOfMotVhiArr
                },
                {
                    name: names[7],
                    type: 'line',
                    yAxisIndex: 5,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: engiRtteSpdArr
                },
                {
                    name: names[8],
                    type: 'line',
                    yAxisIndex: 3,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: engiEngnOilPrsArr
                },
                {
                    name: names[9],
                    type: 'line',
                    yAxisIndex: 2,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: engiWteTpteArr
                },
                {
                    name: names[10],
                    type: 'line',
                    yAxisIndex: 3,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: preAirPrsArr
                },
                {
                    name: names[11],
                    type: 'line',
                    yAxisIndex: 3,
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    data: lastAirPrsArr
                }
            ]
        };

        myChart.setOption(option);
    };

    // DOIT: 2016-12-30 生成 “发动机-外特性曲线图” 图表
    var initExtChaCurveChart = function (data) {

    };


    // DOIT: 2016-12-30 生成 “发动机-发动机功率图” 图表
    var initEnginePowerChart = function (data) {
        // 清空图表
        myChart.clear();

        // 数据处理
        // FIXME: 2017-01-05 数据处理可能还有问题，需要进一步跟进
        var torque = [];
        var capacity = [];

        var item;
        var num1;
        var num2;
        for (var i = 0; i < data.length; i++) {
            item = data[i];

            var engiRtteSpd = (item.engiRtteSpd && item.engiRtteSpd > 0) ? item.engiRtteSpd : 0;
            var maxRefrTorq = (item.maxRefrTorq && item.maxRefrTorq > 0) ? item.maxRefrTorq : 0;

            num1 = accMul(engiRtteSpd, maxRefrTorq);
            num2 = num1 / 9550;

            torque.push([engiRtteSpd, maxRefrTorq]);
            capacity.push([engiRtteSpd, num2.toFixed(2) - 0]);
        }

        var names = ['扭矩', '功率'];
        var units = ['Nm', 'kw'];
        var colors = ['#5AF384', '#4E7CD1'];

        var option = {
            color: colors,
            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = '转速：' + param.value[0] + ' r/min<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                top: '10%',
                bottom: '26%',
                left: '10%',
                right: '10%'
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: names,
                bottom: 10
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 40,
                    end: 60,
                    top: '85%',
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 40,
                    end: 60
                }
            ],
            xAxis: [
                {
                    name: '转速',
                    type: 'value',
//                min: 600,
//                max: 2000,

                    nameLocation: 'middle',
                    nameGap: 30,
                    nameTextStyle: {
                        color: '#666666'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },

                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: units[0],
                    min: 0,
                    max: 500,
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }, {
                    type: 'value',
                    name: units[1],
                    min: 0,
                    max: 250,
                    position: 'right',
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    data: torque
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    data: capacity
                }
            ]
        };

        myChart.setOption(option);
    };


    // DOIT: 2016-12-30 生成 “电池-电压电流图表” 图表
    var initBatteryVoltCurrChart = function (data) {
        // 清空图表
        myChart.clear();

        // 数据处理
        var volt = [];
        var curr = [];

        for (var i = 0; i < data.length; i++) {
            item = data[i];

            volt.push([item.rcrdTime, (item.totalVtg && item.totalVtg > 0) ? item.totalVtg : 0]);
            curr.push([item.rcrdTime, (item.totalEltCrt && item.totalEltCrt > 0) ? item.totalEltCrt : 0]);
        }

        var names = ['总电流', '总电压'];
        var colors = ['#5AF384', '#4E7CD1'];
        var units = ['A', 'V'];

        var option = {
            color: colors,
            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = param.value[0] + '<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                top: '10%',
                bottom: '26%',
                left: '10%',
                right: '10%'
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: names,
                bottom: 10
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 40,
                    end: 60,
                    top: '85%',
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 40,
                    end: 60
                }
            ],
            xAxis: [
                {
                    name: '时间',
                    type: 'time',

                    nameLocation: 'middle',
                    nameGap: 30,
                    nameTextStyle: {
                        color: '#666666'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },

                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: 'A',
                    min: 0,
                    max: 600,
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }, {
                    type: 'value',
                    name: 'V',
                    min: 0,
                    max: 300,
                    position: 'right',
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    data: volt
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    data: curr
                }
            ]
        };

        myChart.setOption(option);
    };


    // DOIT: 2016-12-30 生成 “电池-续航里程分析” 图表
    var initMileageAnalChart = function (data) {
        // 清空图表
        myChart.clear();

        // 数据处理
        var soc = [];
        var enduranceMile = [];

        for (var i = 0; i < data.length; i++) {
            item = data[i];

            soc.push([item.rcrdTime, item.soc ? item.soc : 0]);
            enduranceMile.push([item.rcrdTime, item.enduranceMile ? item.enduranceMile : 0]);
        }

        var names = ['SOC', '续航里程'];
        var colors = ['#5AF384', '#4E7CD1'];
        var units = ['%', 'km'];

        var option = {
            color: colors,
            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = param.value[0] + '<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                top: '10%',
                bottom: '26%',
                left: '10%',
                right: '10%'
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: names,
                bottom: 10
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 40,
                    end: 60,
                    top: '85%',
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 40,
                    end: 60
                }
            ],
            xAxis: [
                {
                    name: '时间',
                    type: 'time',

                    nameLocation: 'middle',
                    nameGap: 30,
                    nameTextStyle: {
                        color: '#666666'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },

                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: units[0],
                    min: 0,
                    max: 100,
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }, {
                    type: 'value',
                    name: units[1],
                    min: 0,
                    max: 2500,
                    position: 'right',
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    data: soc
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    data: enduranceMile
                }
            ]
        };

        myChart.setOption(option);
    };


    // DOIT: 2016-12-30 生成 “电机-电压电流图表” 图表
    var initElecVoltCurrChart = function (data) {
        // 清空图表
        myChart.clear();

        // 数据处理
        var volt = [];
        var curr = [];

        for (var i = 0; i < data.length; i++) {
            item = data[i];

            volt.push([item.rcrdTime, (item.eltMhyCtrlBusbarVtg && item.eltMhyCtrlBusbarVtg > 0) ? item.eltMhyCtrlBusbarVtg : 0]);
            curr.push([item.rcrdTime, (item.eltMhyCtrlBusbarEltCrt && item.eltMhyCtrlBusbarEltCrt > 0) ? item.eltMhyCtrlBusbarEltCrt : 0]);
        }

        var names = ['电流', '电压'];
        var colors = ['#5AF384', '#4E7CD1'];
        var units = ['mA', 'V'];

        var option = {
            color: colors,
            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = param.value[0] + '<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                top: '10%',
                bottom: '26%',
                left: '10%',
                right: '10%'
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: names,
                bottom: 10
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 40,
                    end: 60,
                    top: '85%',
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 40,
                    end: 60
                }
            ],
            xAxis: [
                {
                    name: '时间',
                    type: 'time',

                    nameLocation: 'middle',
                    nameGap: 30,
                    nameTextStyle: {
                        color: '#666666'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },

                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: units[0],
                    min: 0,
                    max: 3000,
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }, {
                    type: 'value',
                    name: units[1],
                    min: 0,
                    max: 3000,
                    position: 'right',
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    data: volt
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    data: curr
                }
            ]
        };

        myChart.setOption(option);
    };


    // DOIT: 2016-12-30 生成 “电机-车速转矩图表” 图表
    var initElecSpeedTorqueChart = function (data) {
        // 清空图表
        myChart.clear();

        // 数据处理
        var spdOfMotVhi = [];
        var eltMhyActualTorque = [];

        for (var i = 0; i < data.length; i++) {
            item = data[i];

            spdOfMotVhi.push([item.rcrdTime, item.spdOfMotVhi ? item.spdOfMotVhi : 0]);
            eltMhyActualTorque.push([item.rcrdTime, item.eltMhyActualTorque ? item.eltMhyActualTorque : 0]);
        }

        var names = ['车速', '转矩'];
        var colors = ['#5AF384', '#4E7CD1'];
        var units = ['km/h', 'Nm'];

        var option = {
            color: colors,
            tooltip: {
                trigger: 'axis',
                formatter: function (params) {
                    console.log(params);

                    var fmtStr = '',
                        param;
                    for (var i = 0; i < params.length; i++) {
                        param = params[i];

                        if (i == 0) {
                            fmtStr = param.value[0] + '<br/>';
                        }

                        fmtStr += '<span style="width: 15px; height: 10px;display: inline-block;margin-right: 5px; background-color: ' + param.color + ';"></span>'
                            + param.seriesName + '：' + param.value[1] + ' ' + units[param.seriesIndex] + '<br/>';
                    }
                    return fmtStr;
                }
            },
            grid: {
                top: '10%',
                bottom: '26%',
                left: '10%',
                right: '10%'
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data: names,
                bottom: 10
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 40,
                    end: 60,
                    top: '85%',
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 40,
                    end: 60
                }
            ],
            xAxis: [
                {
                    name: '时间',
                    type: 'time',

                    nameLocation: 'middle',
                    nameGap: 30,
                    nameTextStyle: {
                        color: '#666666'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },

                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: units[0],
                    min: 0,
                    max: 150,
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }, {
                    type: 'value',
                    name: units[1],
                    min: 0,
                    max: 2500,
                    position: 'right',
                    axisLine: {
                        lineStyle: {
                            color: '#c0c0c0',
                            width: 1
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#666666'
                        }
                    },
                    nameTextStyle: {
                        color: '#666666'
                    }
                }
            ],
            series: [
                {
                    name: names[0],
                    type: 'line',
                    data: spdOfMotVhi
                },
                {
                    name: names[1],
                    type: 'line',
                    yAxisIndex: 1,
                    data: eltMhyActualTorque
                }
            ]
        };

        myChart.setOption(option);
    };


});